#include "Delay.h"

volatile static uint32_t delay;

/*!
    \brief    configure systick
    \param[in]  none
    \param[out] none
    \retval     none
*/
void systick_config(void)
{
    /* setup systick timer for 1000Hz interrupts */
    if(SysTick_Config(SystemCoreClock / 1000000U)) {
        /* capture error */
        while(1) {
        }
    }
    /* configure the systick handler priority */
    NVIC_SetPriority(SysTick_IRQn, 0x00U);
}

/*!
    \brief    delay a time in milliseconds
    \param[in]  count: count in milliseconds
    \param[out] none
    \retval     none
*/
void Delay_ms(uint32_t count)
{
    delay = count *1000;

    while(0U != delay) {
    }
}

void Delay_us(uint32_t count)
{
    delay = count;

    while(0U != delay) {
    }
}

/**
  * @brief  秒级延时
  * @param  xs 延时时长，范围：0~4294967295
  * @retval 无
  */
void Delay_s(uint32_t xs)
{
	while(xs--)
	{
		Delay_ms(1000);
	}
} 

/*!
    \brief    delay decrement
    \param[in]  none
    \param[out] none
    \retval     none
*/
void Delay_decrement(void)
{
    if(0U != delay) {
        delay--;
    }
}